const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');

// Swagger 定义
const swaggerDefinition = {
  openapi: '3.0.0',
  info: {
    title: '隧道系统API文档',
    version: '1.0.0',
    description: '隧道管理系统后端API接口文档',
    contact: {
      name: 'API Support',
      email: 'support@tunnel-system.com'
    }
  },
  servers: [
    {
      url: 'http://localhost:3000/api',
      description: '开发环境服务器'
    }
  ],
  components: {
    securitySchemes: {
      bearerAuth: {
        type: 'http',
        scheme: 'bearer',
        bearerFormat: 'JWT'
      }
    },
    schemas: {
      LoginResponse: {
        type: 'object',
        properties: {
          status: {
            type: 'number',
            example: 200
          },
          username: {
            type: 'string',
            description: '用户名'
          },
          permission: {
            type: 'string',
            description: '权限级别'
          },
          token: {
            type: 'string',
            description: 'JWT令牌'
          }
        }
      },
      ErrorResponse: {
        type: 'object',
        properties: {
          status: {
            type: 'number',
            description: '错误状态码'
          },
          msg: {
            type: 'string',
            description: '错误信息'
          }
        }
      }
    }
  }
};

const options = {
  definition: swaggerDefinition,
  apis: ['./router.js'], // 指向包含Swagger注释的文件
};

const swaggerSpec = swaggerJSDoc(options);

module.exports = {
  swaggerUi,
  swaggerSpec
};